package com.neusoft.bizcore.schedule.service;

import java.util.List;

import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Trigger;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.neusoft.bizcore.schedule.dto.JobDetailDTO;
import com.neusoft.bizcore.web.support.Searchable;

/**
 * job管理
 *
 * @author sunchf
 * @date 2018年12月26日 下午2:02:17
 */
public interface JobMgrService {

    boolean isExists(String name, String gruop);

    /**
     * 查看job信息列表
     *
     * @param pagingDTO
     * @return
     */
    List<JobKey> getJobs(Searchable searchable);

    /**
     * 查看job信息列表
     *
     * @param pagingDTO
     * @return
     */
    Page<JobKey> getJobs(Searchable searchable, Pageable pageable);

    /**
     * 查找job详情
     *
     * @param jobKey
     * @return
     */
    JobDetailDTO getJobDetail(final String name);

    JobDetailDTO getJobDetail(final String name, String group);

    /**
     * 暂停job任务
     *
     * @param jobName
     * @return
     */
    boolean pauseJob(final String name);

    boolean pauseJob(final String name, String group);

    /**
     * 恢复job任务
     *
     * @param jobName
     * @return
     */
    boolean resumeJob(final String name);

    boolean resumeJob(final String name, String group);

    /**
     * 删除job
     *
     * @param jobName
     * @return
     */
    boolean deleteJob(final String name);

    boolean deleteJob(final String name, String group);

    /**
     * 查看对应jobkey的tragger列表
     *
     * @param search
     * @param pageable
     * @return
     */
    Page<Trigger> getTriggers(Searchable searchable, Pageable pageable);

    /**
     * 暂停tragger任务
     *
     * @param triggerKey
     * @return
     */
    boolean pauseTrigger(final String triggerKey);

    /**
     * 恢复tragger任务
     *
     * @param triggerKey
     * @return
     */
    boolean resumeTrigger(final String triggerKey);

    /**
     * 删除trigger
     *
     * @param triggerKey
     * @return
     */
    boolean deleteTrigger(final String triggerKey);

    /**
     * 新建job
     *
     * @param name
     * @param interval
     * @param jobDetail
     * @return
     */
    boolean scheduleJob(String name, Long interval, JobDetail jobDetail);

    boolean scheduleJob(String name, Long interval, JobDetail jobDetail, int priority);

    boolean scheduleJob(String name, String group, Long interval, JobDetail jobDetail);

    boolean scheduleJob(String name, String group, Long interval, JobDetail jobDetail, int priority);

    /**
     * 周期变更更新job
     *
     * @param name
     * @param interval
     * @return
     */
    boolean rescheduleJob(String name, Long interval);

    boolean rescheduleJob(String name, String group, Long interval);

    /**
     * 新建cronjob
     *
     * @param keyword 任务唯一标识
     * @param cronExpression cron表达式
     * @param jobDetail 任务详情
     * @return
     */
    boolean scheduleCronJob(String keyword, String cronExpression, JobDetail jobDetail);

}
